<template>
    <el-dialog title="新增角色" :visible.sync="dialog" width="30%" :before-close="handleClose">
        <el-form :model="roleForm"  ref="roleForm" label-width="80px">
            <el-form-item label="角色名称" prop="roleName">
                <el-input v-model="roleForm.roleName"></el-input>
            </el-form-item>
            <el-form-item label="角色描述" prop = "roleDes">
                <el-input v-model="roleForm.roleDes"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="handleClose">取 消</el-button>
            <el-button type="primary" @click="addSumbit">确定</el-button>
        </span>
    </el-dialog>
</template>
<script>
export default {
    data() {
        return {
            roleForm: {
                roleName: '',
                roleDes: ''
            }
        }
    },
    props: {
        dialog: {
            type: Boolean,
            default: false
        }
    },
    methods: {
        //新增角色
        addSumbit() {
            let newRoleName = this.roleForm.roleName;
            let newRoleDesc = this.roleForm.roleDes;
            let data = {
                "roleName": newRoleName,
                "roleDes": newRoleDesc
            }
            this.$http({
                method: 'post',
                url: 'admin/role/save',
                Headers: {
                    'Content-Type': 'application/json'
                },
                data: data
            }).then(res => {
                let result = res.data;
                if (result.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '操作成功'
                    })
                    //关闭弹窗
                    this.handleClose();
                }
            })
        },
        //关闭弹窗方法
        handleClose() {
            this.$emit("insertDialogFormVisible", false);
        }
    }
}
</script>